{%TEMPLATE->struct/head%}
{%TEMPLATE->struct/menu%}
<h2>Import Supertask</h2>
{%TEMPLATE->struct/messages%}
<hr>
<h3>Masks</h3>
<div class="alert alert-info">
	<b>Information:</b><br>
	For every imported mask there will be a pre-conf task created which is then included in the newly created supertask.
</div>
<form class='form-inline' action="supertasks.php" method="POST">
	<input type='hidden' name='action' value='[[$DSupertaskAction::IMPORT_SUPERTASK]]'>
	<input type="hidden" name="csrf" value="[[csrf]]">
  <div class="table-responsive">
    <table class="table table-bordered">
			<tr>
				<td style="width: 150px;">Name:</td>
				<td>
					<input type='text' name='name' class='form-control' title="Name">
				</td>
			</tr>
			<tr>
				<td>Are small tasks:</td>
				<td>
					<select name="isSmall" class="form-control" title="Small Task">
						<option value="0">No</option>
						<option value="1">Yes</option>
					</select>
				</td>
			</tr>
			<tr>
				<td style="width: 150px;">Max Agents:</td>
				<td>
					<input type='text' name='maxAgents' style='width: 60px;' value='0' class='form-control' title="Max Agents">
				</td>
			</tr>
			<tr>
				<td>Are CPU tasks:</td>
				<td>
					<select name="isCpu" class="form-control" title="CPU Task">
						<option value="0">No</option>
						<option value="1">Yes</option>
					</select>
				</td>
			</tr>
      <tr>
				<td>Use optimized flag (-O):</td>
				<td>
					<select name="optimized" class="form-control" title="Optimized">
						<option value="0">No</option>
						<option value="1">Yes</option>
					</select>
				</td>
			</tr>
      <tr>
				<td>Benchmark type:</td>
				<td>
					<select name="benchtype" class="form-control" title="Benchmark">
						<option value="speed">Speed</option>
						<option value="run">Runtime</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>Cracker Binary which is used to run this task:</td>
				<td>
					<select name="crackerBinaryTypeId" class="form-control" title="Cracker Binary">
						{{FOREACH crackerBinaryType;[[crackerBinaryTypes]]}}
							<option value="[[crackerBinaryType.getId()]]">[[crackerBinaryType.getTypeName()]]</option>
						{{ENDFOREACH}}
					</select>
				</td>
			</tr>
			<tr>
				<td>Insert masks</td>
				<td>
					<textarea name="masks" class="form-control" cols="100" rows="20" placeholder="Paste your Hashcat mask lines here. Format should be according to .hcmask files..."></textarea>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' value="Create Supertask">
				</td>
			</tr>
		</table>
  </div>
</form>
<hr>
<h3>Wordlist/Rule Bulk</h3>
<div class="alert alert-info">
	<b>Information:</b><br>
	For every file selected in the iteration column it will create a subtask with having 'FILE' replaced with the actual file.
</div>
<form action="supertasks.php" method="POST">
	<input type='hidden' name='action' value='[[$DSupertaskAction::BULK_SUPERTASK]]'>
	<input type="hidden" name="csrf" value="[[csrf]]">
  <div class="row">
    <div class='col-md-7'>
      <div class="table-responsive">
        <table class="table table-bordered">
			    <tr>
				    <td style="width: 150px;">Name:</td>
				    <td>
					    <input type='text' name='name' class='form-control' title="Name">
				    </td>
			    </tr>
			    <tr>
				    <td>Are small tasks:</td>
				    <td>
					    <select name="isSmall" class="form-control" title="Small Task">
						    <option value="0">No</option>
						    <option value="1">Yes</option>
					    </select>
				    </td>
			    </tr>
          <tr>
            <td>Max Agents:</td>
            <td>
              <input type='text' name='maxAgents' value='0' class='form-control' title="Max Agents">
            </td>
          </tr>
			    <tr>
				    <td>Are CPU tasks:</td>
				    <td>
					    <select name="isCpu" class="form-control" title="CPU Task">
						    <option value="0">No</option>
						    <option value="1">Yes</option>
					    </select>
				    </td>
			    </tr>
          <tr>
				    <td>Benchmark type:</td>
				    <td>
					    <select name="benchtype" class="form-control" title="Benchmark">
						    <option value="speed">Speed</option>
						    <option value="run">Runtime</option>
					    </select>
				    </td>
			    </tr>
			    <tr>
				    <td>Cracker Binary which is used to run this task:</td>
				    <td>
					    <select name="crackerBinaryTypeId" class="form-control" title="Cracker Binary">
						    {{FOREACH crackerBinaryType;[[crackerBinaryTypes]]}}
							    <option value="[[crackerBinaryType.getId()]]">[[crackerBinaryType.getTypeName()]]</option>
						    {{ENDFOREACH}}
					    </select>
				    </td>
			    </tr>
			    <tr>
				    <td style="width: 200px;">Base Command (use FILE where it should be iterated over the selection):</td>
				    <td>
					    <input type='text' id="cmdLine" name='command' class='form-control' title="Base Command" value="[[SConfig::getInstance()->getVal([[$DConfig::HASHLIST_ALIAS]])]] ">
				    </td>
			    </tr>
			    <tr>
				    <td colspan="2">
					    <input type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' value="Create Supertask">
				    </td>
			    </tr>
		    </table>
      </div>
    </div>
    <div class="col-md-5">
      <div class='btn-toolbar my-1'>
        <div class='btn-group'>
          <button id="ruleButton" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' onclick="return toggleFiles('rules')">Rules</button>
          <button id="wordlistButton" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active' onclick="return toggleFiles('wordlists')">Wordlists</button>
          <button id="otherButton" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' onclick="return toggleFiles('other')">Other</button>
        </div>
      </div>
      <div id="rules">
        <div class="card">
          <div class="table-responsive">
            <table class="table table-bordered">
              <tr>
                <th>Base</th>
                <th>Iterate</th>
                <th>Filename</th>
                <th>Size</th>
              </tr>
              {{FOREACH file;[[rules]]}}
                <tr>
                  <td>
                    <input title="Use File" type="checkbox" onChange="assignFile('cmdLine',this.checked,'[[file.getVal('file').getFilename()]]', 'rule');" name="basefile[]" value="[[file.getVal('file').getId()]]">
                  </td>
                  <td>
                    <input title="Use File" type="checkbox" name="iterfile[]" value="[[file.getVal('file').getId()]]">
                  </td>
                  <td>
                    [[file.getVal('file').getFilename()]]
                    {{IF [[file.getVal('file').getIsSecret()]] == 1}}
                      <span class="fas fa-lock" aria-hidden="true"></span>
                    {{ENDIF}}
                  </td>
                  <td>
                    [[Util::nicenum([[file.getVal('file').getSize()]])]]B
                  </td>
                </tr>
              {{ENDFOREACH}}
            </table>
          </div>
        </div>
      </div>
      <div id="wordlists">
        <div class="card">
          <div class="table-responsive">
            <table class="table table-bordered">
              <tr>
                <th>Base</th>
                <th>Iterate</th>
                <th>Filename</th>
                <th>Size</th>
              </tr>
              {{FOREACH file;[[wordlists]]}}
                <tr>
                  <td>
                    <input title="Use File" type="checkbox" onChange="assignFile('cmdLine',this.checked,'[[file.getVal('file').getFilename()]]', 'wordlist');" name="basefile[]" value="[[file.getVal('file').getId()]]">
                  </td>
                  <td>
                    <input title="Use File" type="checkbox" name="iterfile[]" value="[[file.getVal('file').getId()]]">
                  </td>
                  <td>
                    [[file.getVal('file').getFilename()]]
                    {{IF [[file.getVal('file').getIsSecret()]] == 1}}
                      <span class="fas fa-lock" aria-hidden="true"></span>
                    {{ENDIF}}
                  </td>
                  <td>
                    [[Util::nicenum([[file.getVal('file').getSize()]])]]B
                  </td>
                </tr>
              {{ENDFOREACH}}
            </table>
          </div>
        </div>
      </div>
      <div id="other">
        <div class="card">
          <div class="table-responsive">
            <table class="table table-bordered">
              <tr>
                <th>Base</th>
                <th>Iterate</th>
                <th>Filename</th>
                <th>Size</th>
              </tr>
              {{FOREACH file;[[other]]}}
                <tr>
                  <td>
                    <input title="Use File" type="checkbox" onChange="assignFile('cmdLine',this.checked,'[[file.getVal('file').getFilename()]]', 'other');" name="basefile[]" value="[[file.getVal('file').getId()]]">
                  </td>
                  <td>
                    <input title="Use File" type="checkbox" name="iterfile[]" value="[[file.getVal('file').getId()]]">
                  </td>
                  <td>
                    [[file.getVal('file').getFilename()]]
                    {{IF [[file.getVal('file').getIsSecret()]] == 1}}
                      <span class="fas fa-lock" aria-hidden="true"></span>
                    {{ENDIF}}
                  </td>
                  <td>
                    [[Util::nicenum([[file.getVal('file').getSize()]])]]B
                  </td>
                </tr>
              {{ENDFOREACH}}
            </table>
          </div>
        </div>
      </div>
      <script type='text/javascript'>
        toggleFiles('wordlists');

        function toggleFiles(show) {
          var wordlist = document.getElementById('wordlists');
          var rule = document.getElementById('rules');
          var other = document.getElementById('other');
          if (show === 'rules') {
            wordlist.style.visibility = "hidden"; // or
            wordlist.style.display = "none";
            other.style.visibility = "hidden"; // or
            other.style.display = "none";
            rule.style.visibility = "visible"; // or
            rule.style.display = "inline";
            document.getElementById("ruleButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active";
            document.getElementById("wordlistButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("otherButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
          }
          else if(show === 'wordlists'){
            wordlist.style.visibility = "visible"; // or
            wordlist.style.display = "inline";
            rule.style.visibility = "hidden"; // or
            rule.style.display = "none";
            other.style.visibility = "hidden"; // or
            other.style.display = "none";
            document.getElementById("ruleButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("wordlistButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active";
            document.getElementById("otherButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
          }
          else if (show === 'other') {
            other.style.visibility = "visible"; // or
            other.style.display = "inline";
            rule.style.visibility = "hidden"; // or
            rule.style.display = "none";
            wordlist.style.visibility = "hidden"; // or
            wordlist.style.display = "none";
            document.getElementById("ruleButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("wordlistButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("otherButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active";
          }
          return false;
        }

        function assignFile(cmdLine, addObject, fileName, type) {
          if (fileName.indexOf('.7z') !== -1) {
            fileName = fileName.substring(0, fileName.length - 2) + '???';
          }
          var cmdObject = document.getElementById(cmdLine);
          if (addObject === true) {
            if (cmdObject.value.indexOf(fileName) === -1) {
              if (cmdObject.value.length > 0 && cmdObject.value.slice(-1) !== ' ') {
                cmdObject.value += ' ';
              }
              if (type === 'rule') {
                cmdObject.value += '-r ';
              }
              cmdObject.value += fileName;
            }
          }
          else {
            if (type === 'rule') {
              cmdObject.value = cmdObject.value.replace('-r ' + fileName, '');
            }
            cmdObject.value = cmdObject.value.replace(fileName, '');
            while (cmdObject.value.slice(-1) === ' ') {
              cmdObject.value = cmdObject.value.substring(0, cmdObject.value.length - 1);
            }
            while (cmdObject.value.substring(0, 1) === ' ') {
              cmdObject.value = cmdObject.value.substring(1);
            }
          }
        }
      </script>
    </div>
  </div>
</form>
{%TEMPLATE->struct/foot%}